/**
 * @author mrdoob / http://mrdoob.com/
 */

import {UIPanel, UIRow, UIHorizontalRule} from '../../js/threejs/libs/ui.js'

import {AddObjectCommand} from '../../js/threejs/commands/AddObjectCommand.js'
import {RemoveObjectCommand} from '../../js/threejs/commands/RemoveObjectCommand.js'
import {MultiCmdsCommand} from '../../js/threejs/commands/MultiCmdsCommand.js'
import {SetMaterialValueCommand} from '../../js/threejs/commands/SetMaterialValueCommand.js'

var MenubarEdit = function (editor) {
  var strings = editor.strings

  var container = new UIPanel()
  container.setClass('menu')

  var title = new UIPanel()
  title.setClass('title')
  title.setTextContent(strings.getKey('menubar/edit'))
  container.add(title)

  var options = new UIPanel()
  options.setClass('options')
  container.add(options)

  // Undo

  var undo = new UIRow()
  undo.setClass('option')
  undo.setTextContent(strings.getKey('menubar/edit/undo'))
  undo.onClick(function () {
    editor.undo()
  })
  options.add(undo)

  // Redo

  var redo = new UIRow()
  redo.setClass('option')
  redo.setTextContent(strings.getKey('menubar/edit/redo'))
  redo.onClick(function () {
    editor.redo()
  })
  options.add(redo)

  // Clear History

  var option = new UIRow()
  option.setClass('option')
  option.setTextContent(strings.getKey('menubar/edit/clear_history'))
  option.onClick(function () {
    if (confirm('The Undo/Redo History will be cleared. Are you sure?')) {
      editor.history.clear()
    }
  })
  options.add(option)

  editor.signals.historyChanged.add(function () {
    var history = editor.history

    undo.setClass('option')
    redo.setClass('option')

    if (history.undos.length == 0) {
      undo.setClass('inactive')
    }

    if (history.redos.length == 0) {
      redo.setClass('inactive')
    }
  })

  return container
}

export {MenubarEdit}
